<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<!DOCTYPE html>
<html lang="en">
<head>
<title><s:message code="app.title" /></title>
<%@ include file="Include.jsp"%>
<script type="text/javascript">
	
	$(document).ready(function() {
		var oTable = $('#userTable').dataTable( {
			 	"bDestroy": true,
		        "bProcessing": false,
		        "iDisplayLength": 10,
		        "bFilter": false,
		        "bLengthChange": false,
		        "aoColumnDefs": [
		          { 'bSortable': false, 'aTargets': [7] }
		       	]
		 	} );
		
		$('#addUser').click(function(){
			$('#userListForm').attr('action','AddUser');
			$('#userListForm').attr('method','get');
			$('#userListForm').submit();
		});
		
	});
	
	function edit(userId){
		$('#userEditForm').attr('action','EditUser?userId='+userId);
		
		$('#userId').val(userId);
		
		$('#userEditForm').attr('method','get');
		$('#userEditForm').submit();
	}
	
</script>
</head>
<body>
	<div class="container">
		<%@ include file="Menu.jsp"%>
		<h2><s:message code="userForm.listheader" /></h2>
		<hr>
		<form:form id="userEditForm" >
			<input type="hidden" id="userId" name="userId" />
		</form:form>
		<form:form id="userListForm" >
		<table class="table table-hover table-bordered" id="userTable">
				<thead>
					<tr>
						<th><s:message code="userForm.firstname" /></th>
						<th><s:message code="userForm.middlename" /></th>
						<th><s:message code="userForm.lastname" /></th>
						<th><s:message code="userForm.address" /></th>
						<th><s:message code="userForm.cellno" /></th>
						<th><s:message code="userForm.teleno" /></th>
						<th><s:message code="userForm.email" /></th>
						<th><s:message code="userForm.isactive" /></th>
						<th><s:message code="userForm.creationdate" /></th>
						<th><s:message code="app.action" /></th>
					</tr>
				</thead>
				
				<tbody>
					<c:if test="${empty userList}">
						<tr>
							<td colspan="8">
								<s:message code="app.norecordsfound" />
							</td>
						</tr>
					</c:if>
					<c:forEach items="${userList}" var="user" >
						<tr>
							<td>
								<c:out value="${user.firstname}"></c:out>
							</td>
							<td>
								<c:out value="${user.middlename}"></c:out>
							</td>
							<td>
								<c:out value="${user.lastname}"></c:out>
							</td>
							<td>
								<c:out value="${user.address}"></c:out>
							</td>
							<td>
								<c:out value="${user.cellno}"></c:out>
							</td>
							<td>
								<c:out value="${user.teleno}"></c:out>
							</td>
							<td>
								<c:out value="${user.email}"></c:out>
							</td>
							<td>
								<c:choose>
								    <c:when test="${user.isactive == 1}">
								       YES
								    </c:when>
								    <c:otherwise>
								        NO
								    </c:otherwise>
								</c:choose>
							</td>
							<td>
								<c:out value="${user.creationdate}"></c:out>
							</td>
							<td>
								<a href="#" onclick="javascript: edit('${user.userid}');" >Edit</a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
		</table>
		<br>
		<br>
		<br>
		<button class="btn btn-primary" type="button" id="addUser">
			<s:message code="userForm.addheader" />
		</button>
		</form:form>
		 <%@ include file="Footer.jsp"%>
	</div>
</body>
</html>